#!/usr/bin/python
#-*-coding: utf-8 -*-

def project (name, libraries=[]):
  libs = [
          'pyLotDiscretizationCommon',
          'pyLotMesh',
          'pyLot',
          'pyLotBase',
          '${UMFPACK_LIBRARY}',
          '${ALGLIB_LIBRARY}',
          ]

  for lib in libs :
    if lib not in libraries : libraries.append(lib)

  variables = {}
  variables['name'] = name
  variables['libraries'] = ' '.join(libraries)

  CMakeLists = """
PROJECT(%(name)s)

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

INCLUDE(FindpyLot OPTIONAL RESULT_VARIABLE PYLOT_MODULE_IMPORTED)

IF(PYLOT_MODULE_IMPORTED)
ELSE(PYLOT_MODULE_IMPORTED)
  MESSAGE (FATAL_ERROR
  "please define CMake var pyLot module path : cmake -DCMAKE_MODULE_PATH=/path/to/pylot/cmake/modules ../src")
ENDIF(PYLOT_MODULE_IMPORTED)

INCLUDE(PylotOptions)
INCLUDE(FindpyLotExternalLibs)
INCLUDE(FindCBLAS)

INCLUDE_DIRECTORIES(${PYLOT_INCLUDE_DIR})
LINK_DIRECTORIES(${PYLOT_LIBRARY_DIR})

AUX_SOURCE_DIRECTORY(. SOURCES)
SET(LINKLIBS %(libraries)s)

IF(BLAS_FOUND)
	LIST(APPEND LINKLIBS ${BLAS_LIBRARY})
ENDIF(BLAS_FOUND)

ADD_EXECUTABLE(../%(name)s ${SOURCES})
TARGET_LINK_LIBRARIES(../%(name)s ${LINKLIBS})

INCLUDE(PylotSummary)
  """ % (variables)

  return CMakeLists
